package com.miya.controller;

import com.miya.entity.User;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @DESC
 * @Author:Caixiaowei
 * @Date:2018/11/22
 * @Time:下午5:01
 */
@RestController
@RequestMapping("/user")
@Data
public class UserController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/getUserList")
    public List<User> getUserList(){
        String sql = "select * from t_user";
        List<User> list = jdbcTemplate.query(sql, new Object[]{}, new BeanPropertyRowMapper<>(User.class));
        System.out.println(list.toString());
        return list;
    }

}
